#include<vector>
#include<iostream>
using std::vector;


class Solution {
public:
    int findKthLargest(vector<int>& nums, int k) {
        
        k = nums.size()-k;
        int lo = 0, hi = nums.size()-1;
        while (true) {
            //std::cout << "lo: " << lo << " hi: " << hi << "\n";
            int j = partition(lo, hi, nums);
            if (j == k) return nums[j];
            else if (j < k) {
                lo = j+1;
            }
            else hi = j-1;
        }
        return 0;
    }

    int partition(int lo, int hi, vector<int>& nums) {
        if (lo == hi) return lo;
        int k = lo;
        if (hi - lo > 1) {
            int k = medianOf3(lo, hi, nums);
            // std::cout << "median: " << nums[k] << "\n";
            exch(lo, k, nums);
        }
        int i = lo;
        int j = hi + 1;
        while (i < j) {
            while (nums[++i] < nums[k]) {if (i == hi) break;}
            while (nums[--j] > nums[k]) {if (j == lo) break;}
            if (i >= j) break;
            exch(i, j, nums);
        }
        exch(lo, j, nums);
        return j;

    }

    void exch(int i, int j, vector<int>& nums) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }

    int medianOf3(int lo, int hi, vector<int>& nums) {
        int mi = (lo + hi) / 2;
        int a = nums[lo];
        int b = nums[mi];
        int c = nums[hi];
        if ((b - a) * (b - c) <= 0) return mi;
        else if ((c - a) * (c - b) <= 0) return hi;
        else return lo;
    }
};


int main() {
    int k;
    std::cin >> k;
    int tmp;
    vector<int> nums;
    while (std::cin >> tmp) nums.push_back(tmp);
    for (auto n: nums) std::cout << n << " ";
    std::cout << "\n";
    // auto res = Solution().medianOf3(0, nums.size()-1, nums);
    auto res = Solution().findKthLargest(nums, k);
    std::cout << res << "\n";
    return 0;
}
